require(['jquery', 'cookie', 'app', "lay"], function ($) {
    require(['vue'], function (Vue) {
        var dic = new Vue({
            el: ".vue-box"
            , data: {
                where: {},
                that: {
                    id: "",
                    name: "",
                    uri: "",
                    type: "",
                    status: "",
                    rule: "",
                    permissionsData: []
                }
            }
            , created: function () {
                this.loadPage();
            }
            , methods: {
                loadPage: function () {
                    load();
                    var toolbar = [];
                    toolbar.push({
                        "clas": "layui-icon layui-icon-add-1",
                        "eve": "ADD",
                        "tit": "新增",
                        "fnc": function (data) {
                            dic.openAdd();
                        }
                    });
                    var tool = [];
                    tool.push({
                        "clas": "layui-btn-danger",
                        "eve": "UPDATE",
                        "tit": "修改",
                        "fnc": function (data) {
                            dic.that = data.data;
                            dic.that['status'] = false;
                            dic.that['type'] = "";
                            dic.that['permissionsData'] = "";
                            dic.openAdd();
                        }
                    });
                    bspVIEW($("#authoritiesTable"), "/oauthuser/DataController/find/all", [
                        {type: 'checkbox'},
                        {type: 'numbers'},
                        {field: 'id', title: 'URLid'},
                        {field: 'name', title: 'URL名称', minWidth: 150},
                        {field: 'uri', title: 'URL'},
                        {templet: '<p>{{d.type.display}}</p>', title: 'URL类型'},
                        {field: 'rule', title: 'shiro规则', align: 'center', width: 150},
                        {
                            templet: '<p>{{# if(d.status==false){ }} 禁用 {{# } }}{{# if(d.status==true){ }} 启用 {{# } }}</p>',
                            align: 'center',
                            width: 100,
                            title: '状态'
                        },
                        {title: '操作', toolbar: '#authoritiesTbBar', align: 'center', width: 120}
                    ], {common: this.where}, toolbar, tool, function (res, curr, count) {

                    });
                },
                seachs: function () {
                    this.where = fromName($(".el-form"));
                    this.loadPage();
                },
                refer: function () {

                },
                openAdd: function () {
                    alrYN($("#admins"), function () {
                        var jon = dic.that;
                        jon['status'] = $('input[name="status"]').next().find("em").text();
                        jon['permissions'] = jon['permissionsData'] instanceof Array ? jon['permissionsData'] : jon['permissionsData'].split(",");
                        var ret = playPost("oauthuser/DataController/data", "", JSON.stringify(jon));
                        alr(ret.msg);
                    }, function () {

                    }, function () {

                    }, "权限修改", 1, ["600px", "350px"]);
                }
            }
        });
    })
});